home *** CD-ROM | disk | FTP | other *** search
/ Oh!X 2001 Spring / Oh!X 2001 Spring Special CD-ROM (Japan) (Track 1).bin / DX8VC / Win32Sample / WINSAMPLE.CPP < prev   
Encoding:
C/C++ Source or Header  |  2001-01-08  |  1.4 KB  |  72 lines

  1. // WIN32アプリケーションサンプル 
  2. // WIN32Sample.cpp
  3.  
  4. #include "stdafx.h"
  5. #define APPNAME "WIN32Sample"
  6.  
  7. HINSTANCE hAppInst;
  8.  
  9. LRESULT CALLBACK    WndProc(HWND, UINT, UINT, LONG);
  10.  
  11. int APIENTRY WinMain(HINSTANCE hInstance,
  12.                      HINSTANCE hPrevInstance,
  13.                      LPSTR     lpCmdLine,
  14.                      int       nCmdShow)
  15. {
  16.      
  17.     WNDCLASS wc;
  18.     HWND hWnd;
  19.     MSG msg;
  20.  
  21.     wc.style=CS_HREDRAW|CS_VREDRAW;
  22.     wc.lpfnWndProc=WndProc;
  23.     wc.cbClsExtra=0;
  24.     wc.cbWndExtra=0;
  25.     wc.hInstance=hInstance;
  26.     wc.hIcon=NULL;
  27.     wc.hCursor=LoadCursor(NULL, IDC_ARROW);
  28.     wc.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
  29.     wc.lpszMenuName=0;
  30.     wc.lpszClassName=APPNAME;
  31.  
  32.     RegisterClass(&wc);
  33.     
  34.     hAppInst=hInstance;
  35.     // ウィンドウクラスの登録
  36.     hWnd=CreateWindowEx(0,APPNAME,APPNAME,WS_OVERLAPPEDWINDOW,
  37.         0,0,640,480,NULL,NULL,hInstance,NULL);
  38.  
  39.     if(!hWnd) return FALSE;
  40.     
  41.     ShowWindow(hWnd, nCmdShow);
  42.     UpdateWindow(hWnd);
  43.  
  44.     // メッセージポンプ
  45.     while(GetMessage(&msg, NULL, 0, 0)){
  46.         TranslateMessage(&msg);
  47.         DispatchMessage(&msg);
  48.     }
  49.     return msg.wParam;
  50. }
  51.  
  52. long FAR PASCAL WndProc(HWND hWnd, UINT message,
  53.                         WPARAM wParam, LPARAM lParam)
  54. {
  55.     switch(message){
  56.     
  57.     case WM_KEYDOWN:
  58.         switch(wParam){
  59.  
  60.     case VK_ESCAPE:
  61.             DestroyWindow(hWnd);
  62.             break;
  63.         }
  64.         return TRUE;
  65.  
  66.     case WM_DESTROY:
  67.         PostQuitMessage(0);
  68.         break;
  69.     }
  70.     return DefWindowProc(hWnd, message, wParam, lParam);
  71. }
  72.